//
//  FWCWelcomeViewController.swift
//  微博项目001
//
//  Created by 樊武超 on 16/4/12.
//  Copyright © 2016年 樊武超. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
class FWCWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setUpUI()
        
        starteAnimation()

    }

    func setUpUI(){
        view.addSubview(backImageView)
        view.addSubview(iconImageView)
        view.addSubview(nameLable)
        
        backImageView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(view.snp_top)
            make.left.equalTo(view.snp_left)
            make.bottom.equalTo(view.snp_bottom)
            make.right.equalTo(view.snp_right)
        }
        
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view.snp_centerX)
            make.centerY.equalTo(view.snp_centerY).offset(-100)
            make.size.equalTo(CGSizeMake(100, 100))
        }
        iconImageView.layer.cornerRadius=50
        iconImageView.layer.masksToBounds=true
        iconImageView.sd_setImageWithURL(FWCHomeViewModel.shareHomeViewModel.iconImageUrl)
    nameLable.snp_makeConstraints { (make) -> Void in
        make.centerX.equalTo(view.snp_centerX)
        make.centerY.equalTo(view.snp_centerY).offset(-100)
        }
   
    }
    func starteAnimation(){
    
       iconImageView.snp_makeConstraints { (make) -> Void in
        make.centerY.equalTo(view.snp_centerY).offset(180)
        }
        
    nameLable.alpha=0
        UIView.animateWithDuration(1.2, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 5, options: .CurveEaseInOut, animations: { () -> Void in
            
            self.loadViewIfNeeded()
            
            }) { (_) -> Void in
            UIView.animateWithDuration(0.6, animations: { () -> Void in
                self.nameLable.alpha=1
                }, completion: { (_) -> Void in
                    
                    UIApplication.sharedApplication().keyWindow?.rootViewController=FWCTabBarViewController()
                    
            })
                
                
        }
    
    
    
    
    }
   lazy var backImageView: UIImageView=UIImageView(image: UIImage(named: "ad_background"))
   lazy var iconImageView: UIImageView=UIImageView(image: UIImage(named: "avatar_default_big"))
   lazy var nameLable: UILabel=UILabel(text: FWCHomeViewModel.shareHomeViewModel.userMessage?.name ?? "", fontSize: 16.0, color: UIColor.darkGrayColor())

}
